﻿namespace DimensionsHelper.ExcelAddIn.Core.Sql;

/// <summary>
/// SQL字段的分类元素码表
/// </summary>
public class CodeMap
{

    private List<CodeMapElement>? _elements;


    /// <summary>
    /// 如果当前码表中包含码号级别，返回<see langword="true"/>
    /// </summary>
    public bool WithLevel { get; private set; }


    /// <summary>
    /// 如果当前码表为空，返回<see langword="true"/>
    /// </summary>
    public bool IsEmpty => _elements == null || _elements.Count == 0;


    /// <summary>
    /// 向当前码表末尾追加一个新的分类元素
    /// </summary>
    /// <param name="element">新的分类元素</param>
    public void AddElement(CodeMapElement element)
    {
        _elements ??= [];
        _elements.Add(element);

        if (element.IsLevel)
        {
            WithLevel = true;
        }
    }


    /// <summary>
    /// 获取保存的分类元素数组
    /// </summary>
    public CodeMapElement[] GetElements() => _elements?.ToArray() ?? [];

}
